mui.init({
	beforeback: function() {
		if(document.getElementById("__MUI_PREVIEWIMAGE").style.display == 'block'){
			document.getElementById("__MUI_PREVIEWIMAGE").style.display = 'none';
			document.getElementById("__MUI_PREVIEWIMAGE").classList.remove('mui-preview-in');
			return false;
		}
		if(document.getElementById('showTanChuang').innerHTML !=''){
			document.getElementById('showTanChuang').innerHTML = '';
			masks.close();
			return false;
		}
		setTimeout(function() {
			window.scrollTo(0, 0);
			blog.udata = blogdata;
			mui('.mui-scroll')[0].style.transform = "translate3d(0px, 0px, 0px)";
		}, 300)

	}
});
mui.previewImage();

plus.webview.currentWebview().setStyle({
	scrollIndicator: 'none',
	popGesture: 'none'
});

var tp = true;

var blogdata = {
	user_id: '',
	nick_name: '',
	headimg: '',
	chakan:false
};
var webtitle = document.getElementsByTagName("title")[0];

var GetUserDataUrl = getApiUrl('http://www.jiaoyou0.cn', 'user/userHomepage');
var blog = new Vue({
	el: '.mui-content',
	data: {
		picshow: false,
		udata: blogdata,
	},
	methods: {
		resetData: function() {
			Object.assign(this.$data, getDefaultData())
		},
		openchongzhi: function() {
			showTanChuang('升级VIP，才可以查看女神的全部私房照！','升级VIP','不看了',2,'page/wallet.html')
		}
	},
	filters: {
		liwpic: function(value) {
			return "../img/gift/" + value + ".png"
		},
		guanzhupic: function(value) {
			if(value == null) {
				return '../img/function/blog_click_no.png'
			} else {
				return '../img/function/blog_click.png'
			}
		},
		guanzhupic: function(value) {
			if(value == null) {
				document.getElementById('liketa').style.backgroundImage = 'url(../img/function/liketa_click_no.png)';
			} else {
				document.getElementById('liketa').style.backgroundImage = 'url(../img/function/liketa_click.png)';
			}
		}
	}
});

if(!isallpay()) {
	document.querySelector('.girl-voice').style.display = 'none';
	document.querySelector('.mlz').style.display = 'none';
	document.querySelector('.zxh').style.display = 'none';
	document.querySelector('.lxfs').style.display = 'none';
	var showp = {
		showpic: true
	};
	blog.picshow = true;
	tp = false;
	document.getElementById("liwubox").style.display = "none";
} else {
	var showp = {
		showpic: false
	};
	blog.picshow = false;
};
if(isvipcoin()){
	blog.picshow = true;
}
var say_Data =[];
var sayhello;
document.addEventListener('PersonalBlog', function(event) {
	showWaiting('加载中…','../')
	blog.udata.user_id = event.detail.uid;
	blog.udata.headimg = event.detail.headimg;
	blog.udata.nick_name = event.detail.nick_name;
	webtitle.innerHTML = blog.udata.nick_name;
	sayhello = plus.storage.getItem('sayhello');
	if(sayhello) {
		say_Data = JSON.parse(sayhello);
	}
	document.getElementsByClassName('girl-say')[0].children[0].setAttribute('src', '../img/function/blog_sayhi1.png');
	mui.each(say_Data, function(key, value) {
		if(value == blog.udata.user_id) {
			//换图片
			document.getElementsByClassName('girl-say')[0].children[0].setAttribute('src', '../img/function/blog_sayhi2.png')
			return false;
		}
	})


	mui.ajax(GetUserDataUrl, {
		type: 'GET',
		dataType: 'json',
		timeout: 3000,
		data: {
			'sid': blog.udata.user_id
		},
		success: function(rsp) {

			plus.nativeUI.closeWaiting()
			mui.extend(true, rsp.data, showp);
			blog.udata = rsp.data;
		},
		error: function(xhr, type, errorThrown) {
			plus.nativeUI.closeWaiting()
			mui.toast('网络不好，重试下吧！')
		}
	})
});

document.getElementsByClassName('girl-say')[0].addEventListener('tap', function() {
	if(this.children[0].getAttribute('src') == '../img/function/blog_sayhi1.png') {
		this.children[0].setAttribute('src', '../img/function/blog_sayhi2.png')
		say_Data.push(blog.udata.user_id);
		plus.storage.setItem('sayhello', JSON.stringify(say_Data));
	} else {
		mui.toast('已打招呼');
	}
})


var guanurl = getApiUrl('http://www.jiaoyou0.cn', 'follow/addFollow');

function guanClick() {
	if(blog.udata.guanzhu) return;
	blog.udata.guanzhu = true;
	mui.ajax({
		type: "post",
		url: guanurl,
		async: true,
		dataType: 'json',
		data: {
			'user_id': configs.user_id,
			'follow_uid': blog.udata.user_id
		},
		success: function(data) {
			if(data.code == 1) {
				blog.udata.fensi = blog.udata.fensi + 1;
			} else {
				mui.toast(data.message)
			}
		}
	})
};

mui('body').on('tap', '.girl-vadio, .girl-voice', function() {
	mui.openWindow({
		url: 'page/Voice.html',
		id: 'Voice',
		extras: {
			name: blog.udata.nick_name,
			headimg: blog.udata.headimg,
			type: "call"
		},
		createNew: false,
		show: {
			autoShow: true
		},
		waiting: {
			autoShow: false,
			title: '正在加载...'
		}
	})
});


var chatPage = null;
mui('body').on('tap', '.girl-siliao', function() {
	var sid = blog.udata.user_id;
	var rheadimg = blog.udata.headimg;
	var title = blog.udata.nick_name;
	if(!chatPage) {
		chatPage = plus.webview.getWebviewById('Msg_Chat')
	};
	mui.fire(chatPage, 'getmessage', {
		id: blog.udata.user_id,
		title: blog.udata.nick_name,
		rheadimg: blog.udata.headimg
	});
	mui.openWindow({
		url: 'html/Msg_Chat.html',
		id: 'Msg_Chat'
	})
});

document.addEventListener('jubao', function(event) {
	mui.openWindow({
		url: 'page/Hei_ziliao.html',
		id: 'ziliao',
		extras: {
			name: blog.udata.nick_name,
			headimg: blog.udata.headimg,
			user_id: blog.udata.user_id
		},
		createNew: false,
		show: {
			autoShow: true
		},
		waiting: {
			autoShow: false,
			title: '正在加载...'
		}
	})
})

mui('body').on('tap', '#person-qq, #person-weixin ,#person-tel', function() {
	var isis = isvipcoin(0);
	if(!tp) isis = true;
	if(isis) {
		blogdata.chakan = true;
		var mmi = this.getAttribute('id');
		switch(mmi) {
			case 'person-qq':
			case 'person-weixin':
			case 'person-tel':
				mui.toast('用户未填写或设置了保密');
				break;
			default:
				mui.toast('用户设置了保密！');
				break
		}
	} else {
		showTanChuang('成为VIP，查看女神的联系方式！','升级VIP','不想获取',2,'page/wallet.html')
	}
});
